        #include <bitset>
        #include <iostream>
        #include <sstream>

        using namespace std;

/*        int main()
        {
            long         a = 'a';
            bitset<10>   b(a);

            cout << "b('a') is " << b << endl;

            ostringstream s;
            s << b;
            string  str = s.str();
            cout<<str<<endl;
            cout << "index 3 in the string is " << str[3] << " but\n"
                 << "index 3 in the bitset is " << b[3] << endl;
        }*/

/*class UPNumber
{
    public:
        UPNumber(){cout << "this is  base  ctor" << endl;};
        virtual void foo(){std::cout<<"this is base foo"<<std::endl;}
    protected:
        virtual ~UPNumber() = 0;
};

UPNumber::~UPNumber(){std::cout<<"this is base dtor "<<std::endl;}

class derived_UPNumber: public UPNumber
{
    public :
        ~derived_UPNumber(){std::cout<<"this is  derived  dtor"<<std::endl;}
        derived_UPNumber(){std::cout<<"this is  derived  ctor"<<std::endl;}
        virtual void bar(){foo();}
    private :
         void foo(){std::cout<<"this is derived foo"<<std::endl;}
};

class dderived_UPNumber: public derived_UPNumber
{
    public :
        ~dderived_UPNumber(){std::cout<<"this is  derived  dtor"<<std::endl;}
        dderived_UPNumber(){std::cout<<"this is  derived  ctor"<<std::endl;}
        void bar(){foo();}
    private :
         void foo(){std::cout<<"this is dddd derived foo"<<std::endl;}
};

int main()
{
	derived_UPNumber  d ;
	dderived_UPNumber  dd ;
	UPNumber*   base = &dd;
	//base->foo();
	(static_cast<UPNumber*>(&dd))->foo();
    (dynamic_cast<UPNumber*>(&dd))->foo();
	(static_cast<derived_UPNumber*>(base))->bar();
    (dynamic_cast<derived_UPNumber*>(base))->bar();
    //(static_cast<UPNumber*>(&dd))->foo();
    //(dynamic_cast<UPNumber*>(&dd))->foo();
}

*/

// dynamic_cast_7.cpp
// compile with: /c /GR
class A {virtual void f();};
class B {virtual void f();};


int  main()
{
       A* pa = new A;
   B* pb = dynamic_cast<B*>(pa);   // fails at runtime, not safe;
   // B not derived from A

}

